
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 01/08/2016 14:35:49
-- Generated from EDMX file: E:\Work\Project\闲么\WD.Db.DAL\Model.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [XMDB];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------


-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Base_CodeData]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Base_CodeData];
GO
IF OBJECT_ID(N'[dbo].[Base_OperateLog]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Base_OperateLog];
GO
IF OBJECT_ID(N'[dbo].[Log4net]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Log4net];
GO
IF OBJECT_ID(N'[dbo].[Rbac_FunctionModel]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Rbac_FunctionModel];
GO
IF OBJECT_ID(N'[dbo].[Rbac_LoginInfo]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Rbac_LoginInfo];
GO
IF OBJECT_ID(N'[dbo].[Rbac_Role]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Rbac_Role];
GO
IF OBJECT_ID(N'[dbo].[Rbac_User]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Rbac_User];
GO
IF OBJECT_ID(N'[dbo].[Rbac_VerifyCode]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Rbac_VerifyCode];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Base_CodeData'
CREATE TABLE [dbo].[Base_CodeData] (
    [ID] int  NOT NULL,
    [CreateTime] datetime  NOT NULL,
    [IsDeleted] bit  NOT NULL,
    [CodeID] char(8)  NOT NULL,
    [CodeName] nvarchar(50)  NULL,
    [CodeType] int  NULL,
    [Sort] int  NOT NULL,
    [EditUser] nvarchar(50)  NOT NULL,
    [EditDate] datetime  NOT NULL,
    [AllId] nvarchar(500)  NOT NULL
);
GO

-- Creating table 'Base_OperateLog'
CREATE TABLE [dbo].[Base_OperateLog] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [OpType] int  NOT NULL,
    [Operating] nvarchar(max)  NULL,
    [Url] varchar(150)  NULL,
    [IP] varchar(15)  NULL,
    [MAC] varchar(50)  NULL,
    [IsDeleted] bit  NOT NULL,
    [CreateTime] datetime  NOT NULL,
    [EditUser] nvarchar(50)  NULL
);
GO

-- Creating table 'Log4net'
CREATE TABLE [dbo].[Log4net] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Level] nvarchar(50)  NULL,
    [Logger] nvarchar(255)  NULL,
    [Host] nvarchar(50)  NULL,
    [CreateTime] datetime  NOT NULL,
    [Thread] nvarchar(255)  NULL,
    [Message] nvarchar(max)  NULL,
    [Exception] nvarchar(max)  NULL,
    [IsDeleted] bit  NOT NULL
);
GO

-- Creating table 'Rbac_FunctionModel'
CREATE TABLE [dbo].[Rbac_FunctionModel] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [ModelID] decimal(18,0)  NOT NULL,
    [ModelName] nvarchar(50)  NOT NULL,
    [ParentID] decimal(18,0)  NULL,
    [Url] varchar(80)  NULL,
    [IsDeleted] bit  NOT NULL,
    [CreateTime] datetime  NOT NULL,
    [EditDate] datetime  NOT NULL,
    [EditUser] nvarchar(50)  NOT NULL,
    [Sort] int  NOT NULL,
    [ModelLevel] int  NOT NULL,
    [ModelType] int  NOT NULL,
    [ModelCode] nvarchar(200)  NULL,
    [Icon] varchar(50)  NULL,
    [ModelCat] int  NULL
);
GO

-- Creating table 'Rbac_LoginInfo'
CREATE TABLE [dbo].[Rbac_LoginInfo] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [CreateTime] datetime  NOT NULL,
    [LoginToken] uniqueidentifier  NOT NULL,
    [LastAccessTime] datetime  NOT NULL,
    [UserID] int  NOT NULL,
    [LoginId] nvarchar(50)  NOT NULL,
    [LoginName] nvarchar(50)  NOT NULL,
    [BusinessPermissionString] nvarchar(4000)  NULL,
    [ClientIP] nvarchar(90)  NULL,
    [EnumLoginAccountType] int  NOT NULL,
    [IsDeleted] bit  NOT NULL
);
GO

-- Creating table 'Rbac_Role'
CREATE TABLE [dbo].[Rbac_Role] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [CreateTime] datetime  NOT NULL,
    [RoleName] nvarchar(50)  NOT NULL,
    [IsDeleted] bit  NOT NULL,
    [EditDate] datetime  NOT NULL,
    [EditUser] nvarchar(50)  NOT NULL
);
GO

-- Creating table 'Rbac_User'
CREATE TABLE [dbo].[Rbac_User] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [UserID] nvarchar(50)  NOT NULL,
    [DepartmentID] decimal(18,0)  NULL,
    [PWD] varchar(64)  NOT NULL,
    [UserName] nvarchar(50)  NULL,
    [LastLoginDate] datetime  NULL,
    [LastLoginIP] varchar(15)  NULL,
    [UserPic] varchar(150)  NULL,
    [IsDeleted] bit  NOT NULL,
    [EditDate] datetime  NOT NULL,
    [EditUser] nvarchar(50)  NOT NULL,
    [CreateTime] datetime  NOT NULL
);
GO

-- Creating table 'Rbac_VerifyCode'
CREATE TABLE [dbo].[Rbac_VerifyCode] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [VerifyText] nvarchar(50)  NULL,
    [Guid] uniqueidentifier  NOT NULL,
    [CreateTime] datetime  NOT NULL,
    [Test] varchar(50)  NULL,
    [IsDeleted] bit  NOT NULL
);
GO

-- Creating table 'Rbac_UserRbac_Role'
CREATE TABLE [dbo].[Rbac_UserRbac_Role] (
    [Rbac_User_ID] int  NOT NULL,
    [Rbac_Role_ID] int  NOT NULL
);
GO

-- Creating table 'Rbac_RoleRbac_FunctionModel'
CREATE TABLE [dbo].[Rbac_RoleRbac_FunctionModel] (
    [Rbac_Role_ID] int  NOT NULL,
    [Rbac_FunctionModel_ID] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [ID] in table 'Base_CodeData'
ALTER TABLE [dbo].[Base_CodeData]
ADD CONSTRAINT [PK_Base_CodeData]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Base_OperateLog'
ALTER TABLE [dbo].[Base_OperateLog]
ADD CONSTRAINT [PK_Base_OperateLog]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Log4net'
ALTER TABLE [dbo].[Log4net]
ADD CONSTRAINT [PK_Log4net]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Rbac_FunctionModel'
ALTER TABLE [dbo].[Rbac_FunctionModel]
ADD CONSTRAINT [PK_Rbac_FunctionModel]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Rbac_LoginInfo'
ALTER TABLE [dbo].[Rbac_LoginInfo]
ADD CONSTRAINT [PK_Rbac_LoginInfo]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Rbac_Role'
ALTER TABLE [dbo].[Rbac_Role]
ADD CONSTRAINT [PK_Rbac_Role]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Rbac_User'
ALTER TABLE [dbo].[Rbac_User]
ADD CONSTRAINT [PK_Rbac_User]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Rbac_VerifyCode'
ALTER TABLE [dbo].[Rbac_VerifyCode]
ADD CONSTRAINT [PK_Rbac_VerifyCode]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [Rbac_User_ID], [Rbac_Role_ID] in table 'Rbac_UserRbac_Role'
ALTER TABLE [dbo].[Rbac_UserRbac_Role]
ADD CONSTRAINT [PK_Rbac_UserRbac_Role]
    PRIMARY KEY NONCLUSTERED ([Rbac_User_ID], [Rbac_Role_ID] ASC);
GO

-- Creating primary key on [Rbac_Role_ID], [Rbac_FunctionModel_ID] in table 'Rbac_RoleRbac_FunctionModel'
ALTER TABLE [dbo].[Rbac_RoleRbac_FunctionModel]
ADD CONSTRAINT [PK_Rbac_RoleRbac_FunctionModel]
    PRIMARY KEY NONCLUSTERED ([Rbac_Role_ID], [Rbac_FunctionModel_ID] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [Rbac_User_ID] in table 'Rbac_UserRbac_Role'
ALTER TABLE [dbo].[Rbac_UserRbac_Role]
ADD CONSTRAINT [FK_Rbac_UserRbac_Role_Rbac_User]
    FOREIGN KEY ([Rbac_User_ID])
    REFERENCES [dbo].[Rbac_User]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Rbac_Role_ID] in table 'Rbac_UserRbac_Role'
ALTER TABLE [dbo].[Rbac_UserRbac_Role]
ADD CONSTRAINT [FK_Rbac_UserRbac_Role_Rbac_Role]
    FOREIGN KEY ([Rbac_Role_ID])
    REFERENCES [dbo].[Rbac_Role]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Rbac_UserRbac_Role_Rbac_Role'
CREATE INDEX [IX_FK_Rbac_UserRbac_Role_Rbac_Role]
ON [dbo].[Rbac_UserRbac_Role]
    ([Rbac_Role_ID]);
GO

-- Creating foreign key on [Rbac_Role_ID] in table 'Rbac_RoleRbac_FunctionModel'
ALTER TABLE [dbo].[Rbac_RoleRbac_FunctionModel]
ADD CONSTRAINT [FK_Rbac_RoleRbac_FunctionModel_Rbac_Role]
    FOREIGN KEY ([Rbac_Role_ID])
    REFERENCES [dbo].[Rbac_Role]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Rbac_FunctionModel_ID] in table 'Rbac_RoleRbac_FunctionModel'
ALTER TABLE [dbo].[Rbac_RoleRbac_FunctionModel]
ADD CONSTRAINT [FK_Rbac_RoleRbac_FunctionModel_Rbac_FunctionModel]
    FOREIGN KEY ([Rbac_FunctionModel_ID])
    REFERENCES [dbo].[Rbac_FunctionModel]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Rbac_RoleRbac_FunctionModel_Rbac_FunctionModel'
CREATE INDEX [IX_FK_Rbac_RoleRbac_FunctionModel_Rbac_FunctionModel]
ON [dbo].[Rbac_RoleRbac_FunctionModel]
    ([Rbac_FunctionModel_ID]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------